<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>日期选择器</title>
    
    <!-- Bootstrap CSS -->
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.3.0/css/bootstrap.min.css" rel="stylesheet">
    
    <!-- Datepicker CSS -->
    <link href="https://cdn.bootcdn.net/ajax/libs/bootstrap-datepicker/1.9.0/css/bootstrap-datepicker.min.css" rel="stylesheet">
</head>
<body>
    <div class="container mt-5">
        <div class="row">
            <div class="col-md-6">
                <div class="form-group">
                    <label for="startDate">开始日期：</label>
                    <input type="text" class="form-control datepicker" id="startDate" placeholder="选择开始日期">
                </div>
            </div>
            <div class="col-md-6">
                <div class="form-group">
                    <label for="endDate">结束日期：</label>
                    <input type="text" class="form-control datepicker" id="endDate" placeholder="选择结束日期" disabled>
                </div>
            </div>
        </div>
    </div>

    <!-- jQuery -->
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <!-- Bootstrap JS -->
    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.3.0/js/bootstrap.bundle.min.js"></script>
    <!-- Datepicker JS -->
    <script src="https://cdn.bootcdn.net/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js"></script>
    <!-- 本地化（中文） -->
    <script src="https://cdn.bootcdn.net/ajax/libs/bootstrap-datepicker/1.9.0/locales/bootstrap-datepicker.zh-CN.min.js"></script>

    <script>
    $(document).ready(function(){
        // 初始化开始日期选择器
        $('#startDate').datepicker({
            format: 'yyyy-mm-dd',
            autoclose: true,
            language: 'zh-CN',
            todayHighlight: true,
            endDate: '+0d'
        }).on('changeDate', function(e){
            // 当开始日期改变时
            let startDate = e.date;
            $('#endDate').datepicker('setStartDate', startDate);
            $('#endDate').prop('disabled', false);
            
            // 如果结束日期早于新的开始日期，则清空结束日期
            let endDate = $('#endDate').datepicker('getDate');
            if(endDate && endDate < startDate) {
                $('#endDate').datepicker('update', '');
            }
        });

        // 初始化结束日期选择器
        $('#endDate').datepicker({
            format: 'yyyy-mm-dd',
            autoclose: true,
            language: 'zh-CN',
            todayHighlight: true,
            startDate: new Date()
        }).on('changeDate', function(e){
            // 当结束日期改变时
            let endDate = e.date;
            $('#startDate').datepicker('setEndDate', endDate);
        });
    });
    </script>
</body>
</html>